const mongoose = require("mongoose");
const { dbUri } = require("../config/config.default");

mongoose.connect(dbUri, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

const db = mongoose.connection;
db.on("error", () => {
  console.log("数据库连接失败");
});
db.once("open", () => {
  console.log("数据库连接成功");
});

module.exports = {
  // 生成到数据库为users数据库
  User: mongoose.model("User", require("./user")),
  // 生成到数据库为articles数据库
  Article: mongoose.model("Article", require("./article")),
};
